﻿using System;
using System.Windows.Forms;

namespace Azure.Online.Proxy {
    public partial class MainForm : Form {

        private readonly ProxyService _service = new ProxyService();

        public MainForm() {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e) {
            Start();
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
            _service.Stop();
        }

        private void Start() {
            _service.Start();
            startMenuItem.Enabled = false;
            stopMenuItem.Enabled = true;
        }

        private void Stop() {
            _service.Stop();
            startMenuItem.Enabled = true;
            stopMenuItem.Enabled = false;
        }

        private void btnStart_Click(object sender, EventArgs e) {
            Start();
        }

        private void btnStop_Click(object sender, EventArgs e) {
            Stop();
        }

        private void exitMenuItem_Click(object sender, EventArgs e) {
            _service.Stop();
            Environment.Exit(0);
        }

        private void startMenuItem_Click(object sender, EventArgs e) {
            Start();
        }

        private void stopMenuItem_Click(object sender, EventArgs e) {
            Stop();
        }
    }
}
